package zhh.tangbao.user.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import zhh.tangbao.user.entity.Authority;
import zhh.tangbao.user.vo.OperateTreeNodeVo;

import java.util.List;
import java.util.Set;

/**
 * @author 粥灰灰
 * @version 1.0
 * @created 2022/8/20
 * @Description 关于功能权限的的dao层操作
 */

@Repository
@Mapper
public interface AuthorityDao extends BaseMapper<Authority> {

    Set<String> listAuthorities(String roleId);

    List<Long> listIdByAuthorityCodes(@Param("codes") List<String> authorities);

    int deleteRoleAuthority(@Param("ids") List<String> ids);

    @Select("SELECT a.authority_code id, a.authority_name label FROM authority a JOIN role_authority ra ON a.id = ra.authority_id AND a.data_status = 1 WHERE ra.role_id = #{roleId}")
    List<OperateTreeNodeVo> listOperateTreeNodeVosByRoleId(@Param("roleId") String roleId);

    int deleteRoleAuthorityRelation(@Param("roleId") String roleId);

    int insertRoleAuthorityRelation(@Param("roleId") String roleId, @Param("a") List<String> authorities);
}
